﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BuySoftwareOnline.Domain.Abstract;

namespace BuySoftwareOnline.Domain.Concrete
{
    public class CustomerRepository : ICustomerRepository
    {
        private BuySoftwareOnlineDataContext context;

        public CustomerRepository()
        {
            context = new BuySoftwareOnlineDataContext();
        }

        public IQueryable<Customer> Customers
        {
            get { return context.Customers; }
        }

        public void SaveCustomer(Customer customer)
        {
            if (customer.CustomerID == 0)
            {
                context.Customers.InsertOnSubmit(customer);
            }
            else
            {
                context.Customers.Attach(customer);
                context.Refresh(System.Data.Linq.RefreshMode.KeepCurrentValues, customer);
            }
            context.SubmitChanges();
        }

        public void DeleteCustomer(Customer customer)
        {
            context.Customers.DeleteOnSubmit(customer);
            context.SubmitChanges();
        }
    }
}
